package shujia.day11;

public class Teacher implements Comparable<Teacher>{
    private String name;
    private int age;

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Teacher o) {
        //按照年龄从小到大排序
        // o - 根的元素【已经存储在树中的元素】
        // this - 待插入的元素
        //显式条件：年龄从小到大排序
        //隐藏条件：年龄一样，姓名不一定一样

//        return this.getAge()-o.getAge();
        int i1 = this.getAge()-o.getAge();
        // 当年龄一样的时候，比较姓名
        return  (i1==0)?this.getName().compareTo(o.getName()):i1;

//        return -10;
    }
}
